package mi.payment.transaction.authorize;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import mi.payment.CardType;
import mi.payment.R;
import mi.payment.transaction.V2SwingCardActivity;
import mi.payment.utils.MoneyUtils;

/**
 * 预授权模块 -- 刷卡界面
 */
public class PreAuthorizeSwingCardActivity extends V2SwingCardActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        startCheckCard();
    }

    private void initView() {
        mTvTitle.setText(R.string.pre_auth);

        String amount = getIntent().getStringExtra("extra_amount");
        long costAmount = MoneyUtils.stringMoney2LongCent(amount);
        setAmount(costAmount);
    }

    @Override
    public void onCheckCardSuccess() {
        boolean isForceInputPwd = getIntent().getBooleanExtra("extra_force_input_pwd", false);
        if (CardType.NFC.getValue() != mTradeData.getPayDetail().cardType || isForceInputPwd) {
            PreAuthInputPWDActivity.startAction(this);
            finish();
        } else {
            DoubleFreePreAuthController controller = new DoubleFreePreAuthController(this, mTradeData);
            controller.operationProcess();
        }
    }

    public static void startAction(Context context, String amount) {
        startAction(context, amount, false);
    }

    public static void startAction(Context context, String amount, boolean isForceInputPwd) {
        Intent intent = new Intent(context, PreAuthorizeSwingCardActivity.class);
        intent.putExtra("extra_amount", amount);
        intent.putExtra("extra_force_input_pwd", isForceInputPwd);
        context.startActivity(intent);
    }


}
